---
title: 'parentsUntil | Cypress Documentation'
description: Get all ancestors of each DOM element in a set of matched DOM elements up to, but not including, the element provided in Cypress.
sidebar_label: parentsUntil
slug: /api/commands/parentsuntil
---

<ProductHeading product="app" />

# parentsUntil

Get all ancestors of each DOM element in a set of matched DOM elements up to,
but not including, the element provided.

:::info

The querying behavior of this command matches exactly how
[`.parentsUntil()`](http://api.jquery.com/parentsUntil) works in jQuery.

:::

## Syntax

```javascript
.parentsUntil(selector)
.parentsUntil(selector, filter)
.parentsUntil(selector, filter, options)
.parentsUntil(element)
.parentsUntil(element, filter)
.parentsUntil(element, filter, options)
```

### Usage

<Icon name="check-circle" color="green" /> **Correct Usage**

```javascript
cy.get('p').parentsUntil('.article') // Yield parents of 'p' until '.article'
```

<Icon name="exclamation-triangle" color="red" /> **Incorrect Usage**

```javascript
cy.parentsUntil() // Errors, cannot be chained off 'cy'
cy.clock().parentsUntil('href') // Errors, 'clock' does not yield DOM elements
```

### Arguments

<Icon name="angle-right" /> **selector _(String selector)_**

The selector where you want finding parent ancestors to stop.

<Icon name="angle-right" /> **element _(DOM node, jQuery Object)_**

The element where you want finding parent ancestors to stop.

<Icon name="angle-right" /> **filter _(String selector)_**

A selector used to filter matching DOM elements.

<Icon name="angle-right" /> **options _(Object)_**

Pass in an options object to change the default behavior of `.parentsUntil()`.

| Option    | Default                                                           | Description                                                                         |
| --------- | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| `log`     | `true`                                                            | Displays the command in the [Command log](/app/core-concepts/open-mode#Command-Log) |
| `timeout` | [`defaultCommandTimeout`](/app/references/configuration#Timeouts) | Time to wait for `.parentsUntil()` to resolve before [timing out](#Timeouts)        |

<HeaderYields />

- `.parentsUntil()` yields the new DOM element(s) it found.
- `.parentsUntil()` is a query, and it is _safe_ to chain further commands.

## Examples

### Selector

#### Find all of the `.active` element's ancestors until `.nav`

```html
<ul class="nav">
  <li>
    <a href="#">Clothes</a>
    <ul class="menu">
      <li>
        <a href="/shirts">Shirts</a>
      </li>
      <li class="active">
        <a href="/pants">Pants</a>
      </li>
    </ul>
  </li>
</ul>
```

```javascript
// yields [ul.menu, li]
cy.get('.active').parentsUntil('.nav')
```

## Rules

<HeaderRequirements />

- `.parentsUntil()` requires being chained off a command that yields DOM
  element(s).

<HeaderAssertions />

- `.parentsUntil()` will automatically
  [retry](/app/core-concepts/retry-ability) until the element(s)
  [exist in the DOM](/app/core-concepts/introduction-to-cypress#Implicit-Assertions).
- `.parentsUntil()` will automatically
  [retry](/app/core-concepts/retry-ability) until all chained assertions have
  passed.

<HeaderTimeouts />

- `.parentsUntil()` can time out waiting for the element(s) to
  [exist in the DOM](/app/core-concepts/introduction-to-cypress#Implicit-Assertions).
- `.parentsUntil()` can time out waiting for assertions you've added to pass.

## Command Log

**_Find all of the `active` element's ancestors until `.nav`_**

```javascript
cy.get('.active').parentsUntil('.nav')
```

The commands above will display in the Command Log as:

<DocsImage
  src="/img/api/parentsuntil/get-all-parents-until-nav-selector.png"
  alt="Command Log parentsUntil"
/>

When clicking on `parentsUntil` within the command log, the console outputs the
following:

<DocsImage
  src="/img/api/parentsuntil/show-parents-until-nav-in-console.png"
  alt="Console Log parentsUntil"
/>

## See also

- [`.parent()`](/api/commands/parent)
- [`.parents()`](/api/commands/parents)
- [`.prevUntil()`](/api/commands/prevuntil)
- [`.nextUntil()`](/api/commands/nextuntil)
